<script type="text/javascript"> 
$(document).ready(function () {
      $(".navigation a").each(function(){ 
      this.href = this.href.replace('sary/asehoy', 'sary/ajax/asehoy');
	  });
	  $(".navigation a").click(function() {
            var thisHref = $(this).attr("href");
            loadPiece(thisHref,"#imagebox"," .navigation a");
            return false;
        });
		
});

function loadPiece(href,divName,divLink) {    
    $(divName).load(href, {}, function(){
        var divPaginationLinks = divName+divLink;
        $(divPaginationLinks).click(function() {     
            var thisHref = $(this).attr("href");
            loadPiece(thisHref,divName,divLink);
            return false;
        });
    });
} 

</script>

<script type="text/javascript"> 
<!--	
	$(document).ready(function(){
		//settings on top
		var domain = '<?php echo  site_url() ?>';
		//function that creates comments
		var commentHandler = function(commentsJSON) {
			$.each(commentsJSON,function(i,comment) {
				var id = 'comment-' + comment.id;
				//create the HTML
				$('<div></div>')
				.addClass('comment')
				.attr('id',id)
				//generate the HTML
				.html('<img src="http://avatar.serasera.org/' + comment.md5username + '.jpg" width="48" height="48" class="thumbnail" /><b>' + comment.n + '.</b> <a href="<?php echo  site_url('profile/') ?>' + comment.username + '">' + comment.username + '</a> ' + comment.date + '<br />' + comment.comment + '<br /><div class="clear"></div>')
				//inject into the container
				.prependTo($('#comments'))
				.hide()
				.slideDown(250);
			});	
		};
		//first replace the more link to addmore div 
		$("a.more").replaceWith("<div class='more' id='load-10'><?php echo  __("Older comments", $module) ?></div>");
		//first, take care of the "load more"
		//when someone clicks on the \"load more\" DIV
		var loadMore = $('div.more');
		var start = loadMore.attr('id').substring(5);
		//load event / ajax
		loadMore.click(function(){
			//add the activate class and change the message
			loadMore.addClass('activate').text('<?php echo __("Loading...", $module) ?>');
			start = loadMore.attr('id').substring(5);
			//begin the ajax attempt
			$.ajax({
				url: '<?php echo  site_url('album/ajax/hevitra/' . $row['sid'] ) ?>/' + start,
				type: 'post',
				dataType: 'json',
				cache: false,
				success: function(responseJSON) {
					//reset the message
					loadMore.text('<?php echo __("Older comments", $module) ?>');
					//increment the current status
					//add in the new comments
					commentHandler(responseJSON);
					loadMore.attr('id', 'load-' + responseJSON['0'].start );
				},
				//failure class
				error: function() {
					//reset the message
					loadMore.text('<?php echo __("No more comments", $module) ?>');
					return false;
				},
				//complete event
				complete: function() {
					//remove the spinner
					loadMore.removeClass('activate');
				}
			});
		});
	});

//-->
</script> 	


<h1><?php echo $title;?></h1>
<?php if (!isset($this->album->album_settings->show_meta) || $this->album->album_settings->show_meta != "N") : ?>
<div id="meta">

<b><?php echo __("Submitted by:", "album") ?></b> <?php echo anchor('profile/' . $row['username'], $row['username']) ?><br />
<b><?php echo __("Album:", "album") ?></b> <?php echo anchor('album/asehoy/' . $row['aid'], $row['album_title']) ?><br/>
<b><?php echo __("Added on:", "album") ?></b> <?php echo date("d/m/Y H:i:s", $row['date']) ?><br/>
<b><?php echo __("Hits:", "album") ?></b> <?php echo $row['view'] ?><br/>

</div>
<?php endif; ?>
<div id="loading" style="visibility: hidden"><?php echo __("Loading...", "album") ?></div>
<div id="imagebox">
<script type="text/javascript"> 
<?php if(isset($row['previous'])): ?>
$.preloadImages("<?php echo $row['previous']['o'] ?>");
<?php endif; ?>
<?php if(isset($row['next'])): ?>
$.preloadImages("<?php echo $row['next']['o'] ?>");
<?php endif; ?>

</script>

<?php if($row['username'] == $this->user->username || $this->user->level['album'] >= LEVEL_EDIT) : ?>
<div class='adminbox'>
<?php echo anchor('album/sary/ampidiro/' . $row['aid'] . '/' . $row['sid'], __("Modify", "album")) ?>
<?php if($row['username'] == $this->user->username || $this->user->level['album'] >= LEVEL_DEL) : ?>
  | <?php echo anchor('album/sary/fafao/' . $row['sid'], __("Delete", "album")) ?>
<?php endif; ?>

</div>

<?php endif; ?>



		<?php if ($notice = $this->session->flashdata('notification')):?>
		<p class="notice"><?php echo $notice;?></p>
		<?php endif;?>
<?php echo anchor('album/asehoy/' . $row['aid'], __("Back to album", "album")); ?>
<div class="navigation">
<?php if(isset($row['previous'])) echo anchor('album/sary/asehoy/' . $row['previous']['sid'], __("Previous", "album")); ?>
<?php if(isset($row['previous']) && isset($row['next'])) echo " | " ?>
<?php if(isset($row['next'])) echo  anchor('album/sary/asehoy/' . $row['next']['sid'], __("Next", "album")); ?>


</div>		
<img src="<?php echo $row['o'] ?>" />	

<script type="text/javascript">
	$("div.share input").click(function(){$(this).select()});
</script>
	
<div class="share"><b><?php echo __("Share:", "album") ?></b> <input type="text" value="<?php echo site_url('album/sary/asehoy/' . $row['sid']) ?>" style="width: 90%; border: none;" />	
</div>

<?php if(isset($row['description'])) echo "<div class='description'>" .  strip_tags($row['description'], '<a><b><i>') ?></div>

<?php if ($hevitra) : ?>
<h1><?php echo __("Comments", "album") ?></h1>
<?php if(count($hevitra) >= 10) : ?>
<?php echo anchor('album/hevitra/vakio/' . $row['sid'] . '/10', __("Older comments", "album"), array("class" => "more", "id" => "load-10")) ?>
<?php endif; ?>

<div id="comments">
<?php $i=1; foreach( $hevitra as $h) : ?>
<div id="comment-<?php echo $h['id'] ?>">
<?php if($row['username'] == $this->user->username || $this->user->level['album'] >= LEVEL_DEL) : ?>
<div class="toolbox">
<a href="<?php echo site_url('album/hevitra/delete/' . $h['id']) ?>" id="<?php echo $h['id'] ?>" class="delete"><img src="http://static.serasera.org/iconset/comment3_(delete)_16x16.gif" width="16" height="16" border="0"/> <?php echo __("Delete", $module) ?></a>
</div>
<?php endif ;?>
<img src="http://avatar.serasera.org/<?php echo md5($h['username']) ?>.jpg" width="48" height="48" class="thumbnail" />
<b><?php echo $start + $i ?>.</b> <a href="<?php echo site_url('profile/' . $h['username']) ?>"><?php echo $h['username'] ?></a> <?php echo date("d/m/Y H:i:s", $h['date']) ?><br/>
<?php echo nl2br(strip_tags($h['comment'], '<b><i>')) ?>
<div class="clear"></div>
</div>
<?php $i++; endforeach; ?>
</div>
<?php endif; ?>

<h1><?php echo __("Add a comment", "album") ?></h1>

<?php 
$allowed = ($this->user->logged_in);
$allowed = $this->plugin->apply_filters('album_comment_allowed', $allowed, $row['username']);
?>

<?php if ($allowed) :?>
<form  enctype="multipart/form-data" class="edit" action="<?php echo site_url('album/hevitra/ampidiro')?>" method="post" accept-charset="utf-8">
<input type='hidden' name='sid' value='<?php echo $row['sid'] ?>' />
		<label for="comment"><?php echo __("Comment:", $module)?></label>
		<textarea name="comment" class="input-textarea" style="height: 100px;"></textarea><br />
		<label for="notify"><?php echo __("Notify me:", $module)?></label>
		<input type="checkbox" name="notify" value="1" /><br />
		<input type="submit" name="submit" value="<?php echo __("Save", $module)?>" class="input-submit" />
		<a href="<?php echo site_url( $this->session->userdata("last_uri") )?>" class="input-submit"><?php echo __("Cancel", $module)?></a>

</form>
<?php elseif(!$this->user->logged_in) : ?>
<p><a id="login" href="<?php echo site_url('member/login') ?>"><?php echo __("Please sign in", "album") ?></a></p>

<?php else: ?>
<p><?php echo __("You are not allowed to comment this photo", $module); ?></p>
<?php endif; ?>
</div>

